package com.wenyu.wenyuyuedu.adapter.circleAdapter;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Intent;
import android.graphics.Color;
import android.support.v7.widget.RecyclerView;
import android.text.Html;
import android.text.Spanned;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.bumptech.glide.Glide;
import com.wenyu.wenyuyuedu.R;
import com.wenyu.wenyuyuedu.activity.LoginActivity;
import com.wenyu.wenyuyuedu.activity.homepage.CircleAttentionActivity;
import com.wenyu.wenyuyuedu.activity.homepage.InvitationDeatil_HeadViewGridView_Viewpager_Activity;
import com.wenyu.wenyuyuedu.base.ListBaseAdapter;
import com.wenyu.wenyuyuedu.bean.circle.CircleDetailBean;
import com.wenyu.wenyuyuedu.bean.homepager.CollectInvitaionBean;
import com.wenyu.wenyuyuedu.bean.homepager.LikeBean;
import com.wenyu.wenyuyuedu.bean.homepager.MyAttentionInformBean;
import com.wenyu.wenyuyuedu.bean.homepager.postDeleteBean;
import com.wenyu.wenyuyuedu.global.ApiWrapper;
import com.wenyu.wenyuyuedu.server.homepager.CollectInvitationServer;
import com.wenyu.wenyuyuedu.server.homepager.Home_AllAtten_Server;
import com.wenyu.wenyuyuedu.server.homepager.Homepage_All_Server;
import com.wenyu.wenyuyuedu.server.homepager.postDeleteServer;
import com.wenyu.wenyuyuedu.utils.AbSharedUtil;
import com.wenyu.wenyuyuedu.utils.DensityUtil;
import com.wenyu.wenyuyuedu.utils.MyToast;
import com.wenyu.wenyuyuedu.utils.SharedConstants;
import com.wenyu.wenyuyuedu.utils.TimeStyle;
import com.wenyu.wenyuyuedu.view.CircleImageView;

import java.util.ArrayList;
import java.util.List;

import cn.sharesdk.onekeyshare.OnekeyShare;
import me.chensir.expandabletextview.ExpandableTextView;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by lenovo on 2017/3/6.
 * 圈子---我的---详情--全部的帖子
 */

public class ListApdaters extends ListBaseAdapter<CircleDetailBean.InfoBeanX.InfoBean> {
    private Activity context;
    private List<CircleDetailBean.InfoBeanX.InfoBean.ForumBookmarkBean> forumBookmark;
    private Intent intent = new Intent();
    private List<String> images;
    private String userUid;
    private CircleDetailBean.InfoBeanX.InfoBean infoBean;
    private String token;
    private String uid;
    private String id;
    private String circle_uid;

    public ListApdaters(Activity mContext) {
        super(mContext);
        this.context = mContext;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View inflate = LayoutInflater.from(context).inflate(R.layout.mycircle_mine_add_item, parent, false);
        return new MyViewHolder(inflate);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {
        infoBean = mDataList.get(position);
        MyViewHolder holderView = (MyViewHolder) holder;
        if (infoBean != null) {
            Glide.with(context)
                    .load(infoBean.getIcon_path())
                    .error(R.drawable.login_logo)
                    .into(holderView.circleImageView);
            /*判断用户是否点赞*/
            int is_support = infoBean.getIs_support();
            holderView.home_all_zancount.setText(infoBean.getSupport_num());
            /*没有点赞*/
            if (is_support == 0) {
                holderView.home_all_zan.setImageResource(R.drawable.home_zan_item);
                holderView.home_all_zancount.setTextColor(Color.parseColor("#c7c7cd"));
            } else if (is_support == 1) {
                holderView.home_all_zan.setImageResource(R.drawable.invitation_selected);
                holderView.home_all_zancount.setTextColor(Color.parseColor("#54d48a"));
            }
            /*发布内容*/
            holderView.tv.setText(infoBean.getContent());
            /*昵称*/
            String uid = infoBean.getUid();
            if (circle_uid.equals(uid)) {
                holderView.hoeme_all_nickname.setText(infoBean.getMember().getNickname());
                holderView.hoeme_all_nickname.setTextColor(context.getResources().getColor(R.color.circle_name));
            } else {
                holderView.hoeme_all_nickname.setText(infoBean.getMember().getNickname());
                holderView.hoeme_all_nickname.setTextColor(context.getResources().getColor(R.color.circle_names));
            }
            /*发布时间*/
            String create_time = infoBean.getCreate_time();
            String s1 = TimeStyle.publishTime(create_time);
            holderView.home_all_releasetime.setText(s1);
            /*获取点赞人数*/
            forumBookmark = infoBean.getForumBookmark();
            int size = forumBookmark.size();
            if (size > 0) {
                holderView.invitation_show_zan.setVisibility(View.VISIBLE);
                String s = AlertLikeCount2(infoBean.getForumBookmark());
                holderView.ll_myclicle_detail_contentzan.setText(s);
                holderView.ll_myclicle_detail_contentzan.setVisibility(View.VISIBLE);
            } else {
                holderView.invitation_show_zan.setVisibility(View.GONE);
                holderView.ll_myclicle_detail_contentzan.setVisibility(View.GONE);
            }
            holderView.invitation_show_zan.setVisibility(size > 0 ? View.VISIBLE : View.INVISIBLE);
            /*5个赞以上显示神和打赏的图片*/
            String support_num = infoBean.getSupport_num();
            int zanCount = Integer.parseInt(support_num);
            /*显示打赏的人数*/
            holderView.home_all_playtourcount.setText(infoBean.getReward_num());
            if (size < 5) {
                holderView.home_all_shen.setVisibility(View.INVISIBLE);
                holderView.home_all_playtour.setVisibility(View.GONE);
                holderView.home_all_playtourcount.setVisibility(View.GONE);
            } else {
                holderView.home_all_shen.setVisibility(View.VISIBLE);
                holderView.home_all_playtour.setVisibility(View.VISIBLE);
                holderView.home_all_playtourcount.setVisibility(View.VISIBLE);
            }
            /*消息的回复量*/
            holderView.home_all_messagecount.setText(infoBean.getReply_num());

            /*内容的图片*/
            for (int i = 0; i < holderView.rlImages.getChildCount(); i++) {
                holderView.rlImages.getChildAt(i).setVisibility(View.GONE);
            }
            if (infoBean.getAll_image() == null || infoBean.getAll_image().size() == 0) {
                holderView.rlImages.setVisibility(View.GONE);
            }
            if (infoBean.getAll_image() != null) {
                for (int ImagePosition = 0; ImagePosition < infoBean.getAll_image().size(); ImagePosition++) {
                    ImageView imageView = (ImageView) holderView.rlImages.getChildAt(ImagePosition);
                    imageView.setVisibility(View.VISIBLE);
                    final int finalImagePosition = ImagePosition;
                    final List<String> all_image = mDataList.get(position).getAll_image();
                    Glide.with(context)
                            .load(all_image.get(ImagePosition))
                            .error(R.drawable.nomal_dynamic)
                            .into(imageView);
                    imageView.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                            intent.setClass(context, InvitationDeatil_HeadViewGridView_Viewpager_Activity.class);
                            intent.putExtra("image_index", finalImagePosition);
                            intent.putStringArrayListExtra("imagesViewpager", (ArrayList<String>) all_image);
                            context.startActivity(intent);
                        }
                    });
                }
            }
            /*评论的条目内容*/
            List<CircleDetailBean.InfoBeanX.InfoBean.PCommentBean> pComment = infoBean.getPComment();
            if (isShowMore(pComment)) {
                holderView.tv_examie_comment.setVisibility(View.VISIBLE);
            } else {
                holderView.tv_examie_comment.setVisibility(View.GONE);
            }
            //获取里边显示的评论
            List<CircleDetailBean.InfoBeanX.InfoBean.PCommentBean> showComment = processComment(pComment, 5);
            holderView.ll_comment_container.removeAllViews();
            // 显示评论信息
            for (CircleDetailBean.InfoBeanX.InfoBean.PCommentBean pCommentBean : showComment) {
                holderView.ll_comment_container.addView(getTextView(pCommentBean.getComment_name(), pCommentBean.getContent()));
                for (CircleDetailBean.InfoBeanX.InfoBean.PCommentBean.SonCommentBean sonCommentBean : pCommentBean.getSon_comment()) {
                    holderView.ll_comment_container.addView(getTextView(sonCommentBean.getComment_name(), pCommentBean.getComment_name(), sonCommentBean.getContent()));
                }
            }


        }
         /*下拉箭头*/
        holderView.home_all_classify.setOnClickListener(classify);
        holderView.home_all_classify.setTag(position);
        /*点赞*/
        holderView.home_all_zan.setOnClickListener(zan);
        holderView.home_all_zan.setTag(position);
        /*打赏*/
        holderView.home_all_playtour.setOnClickListener(playtour);
        holderView.home_all_playtour.setTag(position);
          /*查看评论*/
        holderView.tv_examie_comment.setOnClickListener(comments);
        holderView.tv_examie_comment.setTag(position);
    }

    /**
     * @param comment_name    评论人
     * @param to_comment_name 被回复人
     * @param content         评论内容
     * @return
     */
    private View getTextView(String comment_name, String to_comment_name, String content) {
        Spanned fromHtml = Html.fromHtml("<b>" + "<font color = '#576b95'>" + comment_name + "</font>" + "</b>" + "<font color='#000000'>" + "回复" + "</font>" + "<b>" + "<font color = '#576b95'>" + to_comment_name + "</font>" + "</b>" +
                "<font color='#000000'>" + ":" + "</font>" + "<font color='#000000'>" + content + "</font>");
        TextView textView = new TextView(context);
        textView.setText(fromHtml);
        int paddingTopBottom = DensityUtil.dip2px(context, 5);
        textView.setPadding(0, paddingTopBottom, 0, paddingTopBottom);
        textView.setTextSize(14);
        return textView;
    }

    /**
     * @param comment_name 评论人
     * @param content      评论内容
     * @return
     */
    public TextView getTextView(String comment_name, String content) {
        Spanned fromHtml = Html.fromHtml("<b>" + "<font color = '#576b95'>" + comment_name + ":" + "</font>" + "</b>" + "<font color='#000000'>" + content + "</font>");
        TextView textView = new TextView(context);
        textView.setText(fromHtml);
        int paddingTopBottom = DensityUtil.dip2px(context, 5);
        textView.setPadding(0, paddingTopBottom, 0, paddingTopBottom);
        textView.setTextSize(14);
        return textView;
    }

    /**
     * 是否是查看更多
     *
     * @param pComment
     * @return
     */
    private boolean isShowMore(List<CircleDetailBean.InfoBeanX.InfoBean.PCommentBean> pComment) {
        if (infoBean.lengthType == -1) {
            int allitem = 0;
            if (pComment != null) {
                for (int i = 0; i < pComment.size(); i++) {
                    allitem++;
                    List<CircleDetailBean.InfoBeanX.InfoBean.PCommentBean.SonCommentBean> son_comment = pComment.get(i).getSon_comment();
                    if (son_comment != null) {
                        allitem += son_comment.size();
                    }
                }
            }
            if (allitem > 5) {
                infoBean.lengthType = 1;
            } else {
                infoBean.lengthType = 2;
            }
        }

        if (infoBean.lengthType == 1) {
            return true;
        } else {
            return false;
        }
    }

    /**
     * 处理评论数据
     * 删除不需要显示的
     *
     * @param pComment
     * @param length
     */
    private List<CircleDetailBean.InfoBeanX.InfoBean.PCommentBean> processComment(List<CircleDetailBean.InfoBeanX.InfoBean.PCommentBean> pComment, int length) {
        int allCommentSize = 0;
        if (pComment != null) {
            int pCommentSize = pComment.size();
            for (int i = 0; i < pCommentSize; i++) {
                if (allCommentSize >= length) {
                    while (pCommentSize > i) {
                        pComment.remove(i);
                        pCommentSize = pComment.size();
                    }
                    break;
                }
                allCommentSize++;
                List<CircleDetailBean.InfoBeanX.InfoBean.PCommentBean.SonCommentBean> son_comment = pComment.get(i).getSon_comment();
                if (son_comment != null) {
                    int sonSize = son_comment.size();
                    if (sonSize + allCommentSize >= length) {
                        int subIndex = length - allCommentSize;
                        while (sonSize > subIndex) {
                            son_comment.remove(subIndex);
                            sonSize = son_comment.size();
                        }
                        allCommentSize = length;
                    } else {
                        allCommentSize += sonSize;
                    }
                }
            }
        }
        return pComment;
    }

    /*下拉箭头*/
    public View.OnClickListener classify = new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            int chenkPosition = (int) view.getTag();
            CircleDetailBean.InfoBeanX.InfoBean infoBean = mDataList.get(chenkPosition);
            uid = infoBean.getUid();
            id = infoBean.getId();
            if (userUid.equals(uid)) {
                //用户自己的帖子
                MyShowDownDialog(uid, id, chenkPosition);
            } else {
                /*别人的帖子*/
                showDownDialog(uid, id);
            }
        }
    };
    /*显示向下的箭头---自己的帖子的dialog*/
    private Dialog MyDdownDialog;

    private void MyShowDownDialog(final String uid, final String id, final int position) {
        View view = context.getLayoutInflater().inflate(R.layout.my_down_dialog,
                null);
        MyDdownDialog = new Dialog(context, R.style.transparentFrameWindowStyle);
        MyDdownDialog.setContentView(view, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
                ViewGroup.LayoutParams.WRAP_CONTENT));
        /*收藏*/
        TextView collect = (TextView) view.findViewById(R.id.collect);
        collect.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                collectInvitation(id);
            }
        });
        /*分享*/
        Button delete = (Button) view.findViewById(R.id.delete);
        delete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                showShare();
                MyDdownDialog.cancel();
            }
        });
        /*删除*/
        Button report = (Button) view.findViewById(R.id.report);
        report.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                 /*删除帖子*/
                postDeleteServer postDeleteServer = ApiWrapper.getInstance().create(postDeleteServer.class);
                Call<postDeleteBean> delete = postDeleteServer.getDelete(token, id, uid);
                delete.enqueue(new Callback<postDeleteBean>() {
                    @Override
                    public void onResponse(Call<postDeleteBean> call, Response<postDeleteBean> response) {
                        postDeleteBean body = response.body();
                        if (body != null) {
                            int code = body.getCode();
                            String msg = body.getMsg();
                            if (code == 1) {
                                if (MyDdownDialog != null) {
                                    MyDdownDialog.cancel();
                                }
                                mDataList.remove(position);
                                notifyDataSetChanged();
                                MyToast.showToast(context, "删除成功", Toast.LENGTH_SHORT);
                            } else if (code == 0) {
                                showLoginDoalog();
                            } else if (code == 2800) {
                                MyToast.showToast(context, msg, Toast.LENGTH_SHORT);
                            } else if (code == 2801) {
                                MyToast.showToast(context, msg, Toast.LENGTH_SHORT);
                            } else if (code == 2802) {
                                MyToast.showToast(context, msg, Toast.LENGTH_SHORT);
                            } else if (code == 2803) {
                                MyToast.showToast(context, msg, Toast.LENGTH_SHORT);
                            } else if (code == 2804) {
                                MyToast.showToast(context, msg, Toast.LENGTH_SHORT);
                            }
                        }
                    }

                    @Override
                    public void onFailure(Call<postDeleteBean> call, Throwable t) {
                        MyToast.showToast(context, "网络异常，请稍后重试！", Toast.LENGTH_SHORT);
                    }
                });
            }
        });

        /*取消*/
        Button cancle = (Button) view.findViewById(R.id.cancel);
        cancle.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                MyDdownDialog.cancel();
            }
        });
        Window window = MyDdownDialog.getWindow();
        // 设置显示动画
        window.setWindowAnimations(R.style.main_menu_animstyle);
        WindowManager.LayoutParams wl = window.getAttributes();
        wl.x = 0;
        wl.y = context.getWindowManager().getDefaultDisplay().getHeight();
        // 以下这两句是为了保证按钮可以水平满屏
        wl.width = ViewGroup.LayoutParams.MATCH_PARENT;
        wl.height = ViewGroup.LayoutParams.WRAP_CONTENT;

        // 设置显示位置
        MyDdownDialog.onWindowAttributesChanged(wl);
        // 设置点击外围解散
        MyDdownDialog.setCanceledOnTouchOutside(true);
        MyDdownDialog.show();
    }

    /*显示向下的箭头---他人的帖子的dialog*/
    private Dialog downDialog;

    private void showDownDialog(final String uid, final String id) {
        View view = context.getLayoutInflater().inflate(R.layout.other_down_dialog,
                null);
        downDialog = new Dialog(context, R.style.transparentFrameWindowStyle);
        downDialog.setContentView(view, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
                ViewGroup.LayoutParams.WRAP_CONTENT));
         /*收藏*/
        TextView collect = (TextView) view.findViewById(R.id.collect);
        collect.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                collectInvitation(id);
            }
        });
        /*分享*/
        Button delete = (Button) view.findViewById(R.id.delete);
        delete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                showShare();
                downDialog.cancel();
            }
        });
        /*举报*/
        Button report = (Button) view.findViewById(R.id.report);
        report.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                reportInvitaionDialog(uid, id);
                downDialog.cancel();
            }
        });
        /*取消*/
        Button cancle = (Button) view.findViewById(R.id.cancel);
        cancle.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                downDialog.cancel();

            }
        });
        Window window = downDialog.getWindow();
        // 设置显示动画
        window.setWindowAnimations(R.style.main_menu_animstyle);
        WindowManager.LayoutParams wl = window.getAttributes();
        wl.x = 0;
        wl.y = context.getWindowManager().getDefaultDisplay().getHeight();
        // 以下这两句是为了保证按钮可以水平满屏
        wl.width = ViewGroup.LayoutParams.MATCH_PARENT;
        wl.height = ViewGroup.LayoutParams.WRAP_CONTENT;

        // 设置显示位置
        downDialog.onWindowAttributesChanged(wl);
        // 设置点击外围解散
        downDialog.setCanceledOnTouchOutside(true);
        downDialog.show();
    }

    /*举报的列表---帖子的*/
    private Dialog respotInvitationDialog;

    private void reportInvitaionDialog(final String uid, final String id) {
        View view = context.getLayoutInflater().inflate(R.layout.invitation_report_dialog,
                null);
        respotInvitationDialog = new Dialog(context, R.style.transparentFrameWindowStyle);
        respotInvitationDialog.setContentView(view, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
                ViewGroup.LayoutParams.WRAP_CONTENT));
        Button cancle = (Button) view.findViewById(R.id.report_cancel);
        Button advertising_grabage = (Button) view.findViewById(R.id.advertising_grabage);
        Button plagiarize = (Button) view.findViewById(R.id.plagiarize);
        Button hostility = (Button) view.findViewById(R.id.hostility);
        Button other = (Button) view.findViewById(R.id.other);
        advertising_grabage.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                InInvitationform(uid, id, 2 + "", 1 + "");
            }
        });
        plagiarize.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                InInvitationform(uid, id, 2 + "", 2 + "");
            }
        });
        hostility.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                InInvitationform(uid, id, 2 + "", 3 + "");
            }
        });
        other.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                InInvitationform(uid, id, 2 + "", 4 + "");
            }
        });
        /*关闭dialog*/
        cancle.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                respotInvitationDialog.cancel();
            }
        });
        Window window = respotInvitationDialog.getWindow();
        // 设置显示动画
        window.setWindowAnimations(R.style.main_menu_animstyle);
        WindowManager.LayoutParams wl = window.getAttributes();
        wl.x = 0;
        wl.y = context.getWindowManager().getDefaultDisplay().getHeight();
        // 以下这两句是为了保证按钮可以水平满屏
        wl.width = ViewGroup.LayoutParams.MATCH_PARENT;
        wl.height = ViewGroup.LayoutParams.WRAP_CONTENT;

        // 设置显示位置
        respotInvitationDialog.onWindowAttributesChanged(wl);
        // 设置点击外围解散
        respotInvitationDialog.setCanceledOnTouchOutside(true);
        respotInvitationDialog.show();
    }

    /*举报的接口-----可以举报帖子--可以举报圈子-=------inform(是圈子还是帖子)--- type(是举报的类型)*/
    private void InInvitationform(String toUid, String ObjectId, String inFormTyoe, String type) {
        Home_AllAtten_Server home_allAtten_server = ApiWrapper.getInstance().create(Home_AllAtten_Server.class);
        Call<MyAttentionInformBean> myAttentionInformBeanCall = home_allAtten_server.postInform(token, toUid, ObjectId, inFormTyoe, type);
        myAttentionInformBeanCall.enqueue(new Callback<MyAttentionInformBean>() {
            @Override
            public void onResponse(Call<MyAttentionInformBean> call, Response<MyAttentionInformBean> response) {
                MyAttentionInformBean body = response.body();
                if (body != null) {
                    int code = body.getCode();
                    if (code == 1) {
                        if (respotInvitationDialog != null) {
                            respotInvitationDialog.cancel();
                        }
                        if (downDialog != null) {
                            downDialog.cancel();
                        }
                        MyToast.showToast(context, "举报成功，等待审核", Toast.LENGTH_SHORT);
                    } else if (code == 0) {
                        showLoginDoalog();
                    } else if (code == 2900) {
                        MyToast.showToast(context, "需要登陆后才可以操作", Toast.LENGTH_SHORT);
                    } else if (code == 2901) {
                        MyToast.showToast(context, "抱歉您的账户被暂时限制了，无法进行此操作", Toast.LENGTH_SHORT);
                    } else if (code == 2902) {

                    } else if (code == 2904) {
                        MyToast.showToast(context, "系统繁忙请稍后再试！", Toast.LENGTH_SHORT);
                    }
                }
            }

            @Override
            public void onFailure(Call<MyAttentionInformBean> call, Throwable t) {
                MyToast.showToast(context, "系统繁忙请稍后再试！", Toast.LENGTH_SHORT);
            }
        });
    }

    /*收藏帖子---他人的帖子*/
    private void collectInvitation(final String id) {
        CollectInvitationServer collectInvitationServer = ApiWrapper.getInstance().create(CollectInvitationServer.class);
        Call<CollectInvitaionBean> collectBean = collectInvitationServer.getCollectBean(token, id, 2 + "", 1 + "");
        collectBean.enqueue(new Callback<CollectInvitaionBean>() {
            @Override
            public void onResponse(Call<CollectInvitaionBean> call, Response<CollectInvitaionBean> response) {
                CollectInvitaionBean body = response.body();
                if (body != null) {
                    int code = body.getCode();
                    String msg = body.getMsg();
                    if (code == 1) {
                        if (MyDdownDialog != null) {
                            MyDdownDialog.cancel();
                        }
                        if (downDialog != null) {
                            downDialog.cancel();
                        }
                        MyToast.showToast(context, "收藏成功", Toast.LENGTH_SHORT);
                    } else if (code == 0) {
                        showLoginDoalog();
                    } else if (code == 2500) {
                        MyToast.showToast(context, msg, Toast.LENGTH_SHORT);
                    } else if (code == 2502) {
                        MyToast.showToast(context, msg, Toast.LENGTH_SHORT);
                    } else if (code == 2505) {
                        MyToast.showToast(context, msg, Toast.LENGTH_SHORT);
                    } else if (code == 2506) {
                        MyToast.showToast(context, msg, Toast.LENGTH_SHORT);
                    } else if (code == 2507) {
                        MyToast.showToast(context, msg, Toast.LENGTH_SHORT);
                    } else if (code == 2508) {
                        MyToast.showToast(context, msg, Toast.LENGTH_SHORT);
                    }
                }
            }

            @Override
            public void onFailure(Call<CollectInvitaionBean> call, Throwable t) {
                MyToast.showToast(context, "系统繁忙，请稍后重试！", Toast.LENGTH_SHORT);
            }
        });
    }

    /*token错误或失效*/
    AlertDialog ad;
    private TextView quxiao;
    private TextView queding;

    private void showLoginDoalog() {

        ad = new AlertDialog.Builder(context).create();
        ad.show();
        Window window = ad.getWindow();
        window.setContentView(R.layout.dailog_login);
        quxiao = (TextView) window.findViewById(R.id.dialog_login_quxiao);
        queding = (TextView) window.findViewById(R.id.dialog_login_queding);
        quxiao.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ad.dismiss();
            }
        });
        queding.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                AbSharedUtil.putString(context, SharedConstants.USER_TOKEN, "");
                intent.setClass(context, LoginActivity.class);
                context.startActivity(intent);
                ad.dismiss();
            }
        });
    }

    /*点赞*/
    public View.OnClickListener zan = new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            int chenkPosition = (int) view.getTag();
            Intent getIntent = context.getIntent();
            /*当前登录用户的uid*/
            String login_find_uid = getIntent.getStringExtra("login_find_uid");
            /*创建帖子的uid*/
            String uid = mDataList.get(chenkPosition).getUid();
            /*创建帖子的id*/
            String id = mDataList.get(chenkPosition).getId();
            /*判断是自己的帖子还是自己的帖子*/
            dianZan(id, chenkPosition);
        }
    };

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position, List payloads) {

    }

    /*点赞*/
    private void dianZan(String invitationId, final int position) {
    /*别人的帖子*/
        final String nickname = AbSharedUtil.getString(context, SharedConstants.USER_NICKNAME);
        int type = 1;
        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl("http://www.iwenyu.cn/forum/index/dobookmark.html/")
                .addConverterFactory(GsonConverterFactory.create())
                .build();
        Homepage_All_Server homepage_all_server1 = retrofit.create(Homepage_All_Server.class);
        Call<LikeBean> like1 = homepage_all_server1.getLike(token, Integer.parseInt(invitationId), 1);
        like1.enqueue(new Callback<LikeBean>() {
            @Override
            public void onResponse(Call<LikeBean> call, Response<LikeBean> response) {
                LikeBean body = response.body();
                if (body != null) {
                    int code = body.getCode();
                    if (code == 1) {
                        /*当前用户的昵称*/
                        String name = AbSharedUtil.getString(context, SharedConstants.USER_NICKNAME);
                        MyToast.showToast(context, "点赞成功", Toast.LENGTH_SHORT);
                    /*    zanNickName.clear();
                        zanNickName.add(0, nickname);
                        AlertLikeCount2(infoBean.getForumBookmark());*/
                        CircleDetailBean.InfoBeanX.InfoBean infoBean = mDataList.get(position);
                        List<CircleDetailBean.InfoBeanX.InfoBean.ForumBookmarkBean> forumBookmark = infoBean.getForumBookmark();
                        if (forumBookmark != null) {
                            CircleDetailBean.InfoBeanX.InfoBean.ForumBookmarkBean bean = new CircleDetailBean.InfoBeanX.InfoBean.ForumBookmarkBean();
                            bean.setNickname(name);
                            bean.setUid(userUid);
                            forumBookmark.add(bean);
                            infoBean.setForumBookmark(forumBookmark);
                        } else {
                            forumBookmark = new ArrayList<CircleDetailBean.InfoBeanX.InfoBean.ForumBookmarkBean>();
                            CircleDetailBean.InfoBeanX.InfoBean.ForumBookmarkBean bean = new CircleDetailBean.InfoBeanX.InfoBean.ForumBookmarkBean();
                            bean.setNickname(name);
                            bean.setUid(userUid);
                            forumBookmark.add(bean);
                        }
                        infoBean.setIs_support(1);
                        notifyItemChanged(position);

                    } else if (code == 0) {
                        MyToast.showToast(context, "登陆失效，请重新登陆！", Toast.LENGTH_SHORT);
                    } else if (code == 2300) {
                        MyToast.showToast(context, "需要登陆之后才可以操作", Toast.LENGTH_SHORT);
                    } else if (code == 2301) {
                        MyToast.showToast(context, "抱歉您的账户被暂时限制了，无法进行此操作", Toast.LENGTH_SHORT);
                    } else if (code == 2303) {
                        MyToast.showToast(context, "系统繁忙，请稍后再试", Toast.LENGTH_SHORT);
                    } else if (code == 2302) {
                        MyToast.showToast(context, "您已经操作过了!", Toast.LENGTH_SHORT);
                    } else if (code == 2304) {
                        MyToast.showToast(context, "该帖子不存在或者被冻结", Toast.LENGTH_SHORT);
                    } else if (code == 2305) {
                        MyToast.showToast(context, "该回复不存在或者已经被屏蔽", Toast.LENGTH_SHORT);
                    }
                }
            }

            @Override
            public void onFailure(Call<LikeBean> call, Throwable t) {
                MyToast.showToast(context, "系统繁忙，请稍后再试", Toast.LENGTH_SHORT);
            }
        });
    }

    /*打赏*/
    public View.OnClickListener playtour = new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            int chenkPosition = (int) view.getTag();
            Intent getIntent = context.getIntent();
            intent.setClass(context, CircleAttentionActivity.class);
            CircleDetailBean.InfoBeanX.InfoBean infoBean = mDataList.get(chenkPosition);
            /*对应帖子的id*/
            String id = infoBean.getId();
            intent.putExtra("allattentionid", id);
            /*圈子的名字*/
            String circleName = getIntent.getStringExtra("circleName");
            intent.putExtra("allattentiontitle", circleName);
            /*创建帖子的uid*/
            String uid = infoBean.getUid();
            intent.putExtra("allattentionnicknameuid", uid);
            /*发帖人的昵称*/
            String nickname = infoBean.getMember().getNickname();
            intent.putExtra("allattentionnickname", nickname);
              /*创建圈子人的uid*/
            intent.putExtra("create_circle_uid", circle_uid);
            context.startActivity(intent);
        }
    };
    /*点击查看更多时的点击事件*/
    public View.OnClickListener comments = new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            int chenkPosition = (int) view.getTag();
            intent.setClass(context, CircleAttentionActivity.class);
            CircleDetailBean.InfoBeanX.InfoBean infoBean = mDataList.get(chenkPosition);
            /*对应帖子的id*/
            String id = infoBean.getId();
            intent.putExtra("allattentionid", id);
            Intent getIntent = context.getIntent();
            /*圈子的名字*/
            String circleName = getIntent.getStringExtra("circleName");
            intent.putExtra("allattentiontitle", circleName);
            /*创建帖子的uid*/
            String uid = infoBean.getUid();
            intent.putExtra("allattentionnicknameuid", uid);
            /*发帖人的昵称*/
            String nickname = infoBean.getMember().getNickname();
            intent.putExtra("allattentionnickname", nickname);
                /*创建圈子人的uid*/
            intent.putExtra("create_circle_uid", circle_uid);
            context.startActivity(intent);
        }
    };

    /*获取用户的userid*/
    public void getUserUid(String userUid, String token, String circle_uid) {
        this.userUid = userUid;
        this.token = token;
        this.circle_uid = circle_uid;
    }

    class MyViewHolder extends RecyclerView.ViewHolder {
        /*头像*/
        private CircleImageView circleImageView;
        /*神贴*/
        private ImageView home_all_shen;
        /*昵称*/
        private TextView hoeme_all_nickname;
        /*发布时间*/
        private TextView home_all_releasetime;
        /*向下的箭头*/
        private ImageView home_all_classify;
        /*内容的文字*/
        private ExpandableTextView tv;
        /*打赏的图片*/
        private ImageView home_all_playtour;
        /*点赞的按钮*/
        private ImageView home_all_zan;
        /*赞的图片显示或隐藏*/
        private ImageView invitation_show_zan;
        /*显示点赞的人名*/
        private TextView ll_myclicle_detail_contentzan;
        /*显示评论的内容*/
        private LinearLayout ll_comment_container;
        /*点击查看更多*/
        private TextView tv_examie_comment;
        private RelativeLayout rlImages;
        private ImageView imageYi;
        private ImageView imageEr;
        private ImageView imageSan;
        private ImageView imageSi;
        private ImageView imageWu;
        private ImageView imageLiu;
        private ImageView imageQi;
        private ImageView imageBa;
        private ImageView imageJiu;
        private TextView home_all_messagecount;
        private TextView home_all_zancount;
        private TextView home_all_playtourcount;

        public MyViewHolder(View itemView) {
            super(itemView);
            circleImageView = (CircleImageView) itemView.findViewById(R.id.home_all_head);
            home_all_shen = (ImageView) itemView.findViewById(R.id.home_all_shen);
            hoeme_all_nickname = (TextView) itemView.findViewById(R.id.hoeme_all_nickname);
            home_all_releasetime = (TextView) itemView.findViewById(R.id.home_all_releasetime);
            home_all_classify = (ImageView) itemView.findViewById(R.id.home_all_classify);
            tv = (ExpandableTextView) itemView.findViewById(R.id.tv);
            home_all_playtour = (ImageView) itemView.findViewById(R.id.home_all_playtour);
            home_all_zan = (ImageView) itemView.findViewById(R.id.home_all_zan);
            invitation_show_zan = (ImageView) itemView.findViewById(R.id.invitation_show_zan);
            ll_myclicle_detail_contentzan = (TextView) itemView.findViewById(R.id.ll_myclicle_detail_contentzan);
            tv_examie_comment = (TextView) itemView.findViewById(R.id.tv_examie_comment);
            ll_comment_container = (LinearLayout) itemView.findViewById(R.id.ll_comment_container);
            rlImages = (RelativeLayout) itemView.findViewById(R.id.rl_images);
            imageYi = (ImageView) itemView.findViewById(R.id.circle_detail_image_yi);
            imageEr = (ImageView) itemView.findViewById(R.id.circle_detail_image_er);
            imageSan = (ImageView) itemView.findViewById(R.id.circle_detail_image_san);
            imageSi = (ImageView) itemView.findViewById(R.id.circle_detail_image_si);
            imageWu = (ImageView) itemView.findViewById(R.id.circle_detail_image_wu);
            imageLiu = (ImageView) itemView.findViewById(R.id.circle_detail_image_liu);
            imageQi = (ImageView) itemView.findViewById(R.id.circle_detail_image_qi);
            imageBa = (ImageView) itemView.findViewById(R.id.circle_detail_image_ba);
            imageJiu = (ImageView) itemView.findViewById(R.id.circle_detail_image_jiu);
            home_all_messagecount = (TextView) itemView.findViewById(R.id.home_all_messagecount);
            home_all_zancount = (TextView) itemView.findViewById(R.id.home_all_zancount);
            home_all_playtourcount = (TextView) itemView.findViewById(R.id.home_all_playtourcount);
        }
    }

    List<String> zanNickName = new ArrayList<>();
    private int sizes;

    /*修改点赞的人数*/
    private void AlertLikeCount() {
        if (forumBookmark != null) {
            for (int zan = 0; zan < forumBookmark.size(); zan++) {
                String nickname = forumBookmark.get(zan).getNickname();
                zanNickName.add(nickname);
                sizes = zanNickName.size();
            }
            if (forumBookmark != null) {
                int size = zanNickName.size() > 12 ? 12 : sizes;
                StringBuilder sb = new StringBuilder();
                for (int j = 0; j < size; j++) {
                    if (j != size - 1) {
                        sb.append(zanNickName.get(j) + "," + " ");
                    } else {
                        sb.append(zanNickName.get(j));
                    }
                    if (zanNickName.size() > 12) {
                        sb.append("等" + zanNickName.size() + "人已赞");
                    }
                    // holderView.ll_myclicle_detail_contentzan.setText(sb.toString());
                }
            }
        }
    }

    /*修改点赞的人数*/
    private String AlertLikeCount2(List<CircleDetailBean.InfoBeanX.InfoBean.ForumBookmarkBean> forumBookmark) {
        ArrayList<String> strings = new ArrayList<>();
        StringBuilder sb = new StringBuilder();
        if (forumBookmark != null) {
            for (int zan = 0; zan < forumBookmark.size(); zan++) {
                String nickname = forumBookmark.get(zan).getNickname();
                strings.add(nickname);
            }
            if (forumBookmark != null) {
                int size = strings.size() > 12 ? 12 : strings.size();
                for (int j = 0; j < size; j++) {
                    if (j != size - 1) {
                        sb.append(strings.get(j) + ", ");
                    } else {
                        sb.append(strings.get(j));
                    }
                    if (strings.size() > 12) {
                        sb.append("等" + strings.size() + "人已赞");
                    }
                }
            }
        }
        return sb.toString();
    }

    /*获取点赞人数*/
    public void addAllZan(List<CircleDetailBean.InfoBeanX.InfoBean.ForumBookmarkBean> forumBookmark) {
        if (forumBookmark != null) {
            forumBookmark.clear();
            this.forumBookmark = forumBookmark;
            notifyDataSetChanged();
        }

    }

    private void showShare() {
        OnekeyShare oks = new OnekeyShare();
        //关闭sso授权
        oks.disableSSOWhenAuthorize();
        oks.setSilent(false);
        oks.setDialogMode();
        // title标题，印象笔记、邮箱、信息、微信、人人网、QQ和QQ空间使用
        oks.setTitle("文鱼阅读");
        // titleUrl是标题的网络链接，仅在Linked-in,QQ和QQ空间使用
        // oks.setTitleUrl("http://sharesdk.cn");
        // text是分享文本，所有平台都需要这个字段
        // oks.setText(content);
        //分享网络图片，新浪微博分享网络图片需要通过审核后申请高级写入接口，否则请注释掉测试新浪微博
        oks.setImageUrl("http://www.iwenyu.cn/Public/images/share.jpg");
        // imagePath是图片的本地路径，Linked-In以外的平台都支持此参数
        //oks.setImagePath("/sdcard/test.jpg");//确保SDcard下面存在此张图片
        // url仅在微信（包括好友和朋友圈）中使用
        // oks.setUrl("http://sharesdk.cn");
        // comment是我对这条分享的评论，仅在人人网和QQ空间使用
        oks.setComment("我是测试评论文本");
        // site是分享此内容的网站名称，仅在QQ空间使用
        oks.setSite("ShareSDK");
        // siteUrl是分享此内容的网站地址，仅在QQ空间使用
        oks.setSiteUrl("http://sharesdk.cn");

        // 启动分享GUI
        oks.show(context);
    }
}
